<template>
    <div>
        <el-card class="card">
            <div class="title">
                <h2 style="text-align: center">学校重点项目进程查看</h2>
            </div>
        </el-card>
        <br />
        <el-card>
            <el-row>
                <el-col :span="4">
                    <el-input v-model="inputName"><template slot="prepend">名称：</template></el-input>
                </el-col>
                <el-col :span="1" style="margin-left: 5px">
                    <el-button type="primary" @click="searchInfoByName">查询</el-button>
                </el-col>
            </el-row>
            <br />
            <el-table :data="tableData" style="width: 100%" border>
                <el-table-column prop="projectName" label="项目名称" width="180"> </el-table-column>
                <el-table-column prop="departmentId" label="部门" width="180"> </el-table-column>
                <el-table-column prop="createUserId" label="创建人">
                    <template slot-scope="scope">
                        {{ getCreateUserName(scope.row.createUserId) }}
                    </template>
                </el-table-column>
                <el-table-column label="报表">
                    <template slot-scope="scope">
                        <div v-for="(item, i) in scope.row.schoolReportFormVos" >
                            <el-button
                                type="warning"
                                @click="viewReportForms(item.reportFormBasicInfo.id)"
                                style="padding: 2px 3px"
                                >{{ formateDate(item.reportFormBasicInfo.projectGenerateTime) }}</el-button
                            >
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <br />
        </el-card>
        <!--查看项目报表-->
        <el-drawer :visible.sync="reportViewDrawer" :with-header="false" size="100%">
            <reportFormsView v-on:cancelCreateReport="cancelCreateReportForm" :reportForm="createReportFormData"></reportFormsView>
        </el-drawer>
    </div>
</template>

<script>
import reportFormApi from '../../../../api/reportForms';
import reportFormsView from '../../../reportForms/reportFormsView';
import moment from 'moment';
export default {
    components: {
        reportFormsView
    },
    data() {
        return {
            pageInfo: {
                pageNum: 1,
                pageSize: 10000
            },
            // 查询的项目名称
            inputName: '',
            tableData: [],
            reportViewDrawer: false,
            // 创建报表获取的数据
            createReportFormData: {}
        };
    },
    methods: {
        cancelCreateReportForm() {
            this.reportViewDrawer = false;
        },
        async viewReportForms(id) {
            await reportFormApi.findReportForm(1, id).then((res) => {

                this.reportViewDrawer = true;
                                setTimeout(() => {
                this.createReportFormData = res.data;
                }, 500);
            });
        },
        // 获取创建人名字
        getCreateUserName(id) {
            let obj = {};
            obj = this.$store.state.teacher.teachers.find((item) => {
                return item.id === id;
            });
            return obj.name;
            // console.log(this.$store.state.teacher.teachers);
        },
        async searchInfoByName() {
            await reportFormApi.getByName(1, this.inputName).then((res) => {
                this.tableData = res.data;
            });
        },
                formateDate: function(time){

            return moment(time).format("YYYY-MM-DD")
        
        }
    },
    created() {
        let payload = {
            pageInfo: this.pageInfo,
            isSchool: 1
        };
        // 获取所有老师信息
        this.$store.dispatch('getTeachers').then((res) => {
            // 获取所有项目信息
            this.$store.dispatch('findAllReport', payload).then((res) => {
                this.tableData = res.data;
                console.log(this.tableData);
            });
        });
    },
    computed: {

    }
};
</script>

<style scoped>
.title {
    border: 1px #bcbcbc;
    width: 50%;
    margin: 0 auto;
}
.card {
    border-radius: 15px;
    width: 50%;
    margin: 0 auto;
}
.el-input {
    width: 80%;
}
/*1.显示滚动条：当内容超出容器的时候，可以拖动：*/
div /deep/ .el-drawer__body {
    overflow: auto;
    /* overflow-x: auto; */
}
</style>